import difflib

from selenium import  webdriver
from selenium.webdriver.common.by import By
from time import sleep

op = webdriver.ChromeOptions()
op.add_experimental_option("excludeSwitches", ["enable-automation"])
op.add_experimental_option("useAutomationExtension", False)
driver = webdriver.Chrome(options = op)

driver.get('http://news.baidu.com/')

firstnews = driver.find_element(By.XPATH, "//*[@id='pane-news']/div/ul/li[1]/strong/a")
content = firstnews.text
url = firstnews.get_attribute("href")
# firstnews.click()
sleep(3)

current = driver.current_window_handle
all_handles = driver.window_handles
driver.switch_to.window(all_handles[1])

title = driver.title
nowurl = driver.currrent_url

if len(content)>10:
    content = content[0:10]
if len(title)>10:
    title = title[0:10]
rate = difflib.SequenceMatcher(None,content,title),quick_ration()
print("相似度：",rate)
print('content',content)
print('title',title)

assert url in nowurl
driver.quit()
# assert content in driver.title
# # print(driver.title)

driver.quit()